using System;

namespace SpellCenter.Core
{
  public class TaskMonitorEventAdaptor : ITaskMonitor
  {
    private int _stepCount;
    private string _stepDescription;
    private int _stepsCompletedCount;
    private bool _isCancelled;

    public event EventHandler TaskStarted = delegate
    {
    };

    public void OnTaskStarted(int subTaskCount)
    {
      _stepCount = subTaskCount;
      _stepDescription = string.Empty;
      _stepsCompletedCount = 0;
      _isCancelled = false;
      TaskStarted.Invoke(this, new EventArgs());
    }

    public int StepCount
    {
      get
      {
        return this._stepCount;
      }
    }

    public event EventHandler StepStarted = delegate
    {
    };
    public void OnStepStarted(string description)
    {
      _stepDescription = description;
      StepStarted.Invoke(this, new EventArgs());
    }

    public string StepDescription
    {
      get
      {
        return this._stepDescription;
      }
    }

    public event EventHandler StepFinished = delegate
    {
    };
    public void OnStepFinished()
    {
      _stepDescription = string.Empty;
      StepFinished.Invoke(this, new EventArgs());
    }

    public int StepsCompletedCount
    {
      get
      {
        return this._stepsCompletedCount;
      }
    }

    public void CancelTask()
    {
      _isCancelled = true;
    }

    public bool IsCancelled
    {
      get
      {
        return this._isCancelled;
      }
    }

    public event EventHandler Finished = delegate
    {
    };
    public void OnTaskFinished()
    {
      _stepDescription = string.Empty;
      Finished.Invoke(this, new EventArgs());
    }
  }
}
